﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Kardex.Register;

namespace University.Workshop.Presentation.Kardex.Register
{
    /// <summary>
    /// Interaction logic for PageSecondStepRegisterKardex.xaml
    /// </summary>
    public partial class PageSecondStepRegisterKardex : Page, ISecondStepForRegisterKardex
    {
        PresenterSecondStepForRegisterKardex pSecondStepForRegisterKardex;
        PresenterRegisterNewKardexView pInternal;
        public PageSecondStepRegisterKardex( PresenterRegisterNewKardexView pExternal)
        {
            pInternal = pExternal;
            InitializeComponent();
            pSecondStepForRegisterKardex = new PresenterSecondStepForRegisterKardex(this);
        }

        public Model.Kardex KardexProductToRegister
        {
            get;
            set;
        }

        public void Update()
        {

            pSecondStepForRegisterKardex.RefreshSquare();
            pSecondStepForRegisterKardex.UpdateData();
        }

        public string SystemMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifySystemMessage(value);
            }
        }

        public string ErrorMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifyErrorMessage(value);
            }
        }

        public void ChargeDataToBasic()
        {
            pSecondStepForRegisterKardex.ChargeDataMedicineProduct();
        }

        public void GoNextPage()
        {
            pInternal.GoStepTwo();
        }

        public void GoBackPage()
        {
        }
        
        public string AllotmentName
        {
            get
            {
                return Allotmentdd.Text;
            }
            set
            {
                Allotmentdd.Text=value;
            }
        }

        public Model.Square SquareSelected
        {
            get
            {
                if (Squaredd.SelectedItem != null)
                    return (Model.Square)Squaredd.SelectedItem;
                else
                    return null;
            }
            set
            {
                
                if (value == null)
                    Squaredd.SelectedItem=null;
                else 
                Squaredd.SelectedValue = ((ICollection<Model.Square>) Squaredd.ItemsSource).First(x=>x.SquareId==value.SquareId);
            }
        }


        public string PersonId
        {
            get
            {
                return PartnerIdTxt.Content.ToString();
            }
            set
            {
                PartnerIdTxt.Content = value;
            }
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "UIActualizarKardex";
        }


        public void setListSquaresAvailable(List<Model.Square> squares)
        {
            Squaredd.ItemsSource = squares;
        }


        public bool EnableAllotmentName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                Allotmentdd.IsEnabled = value;
            }
        }

        private void Squaredd_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            pSecondStepForRegisterKardex.SelectedSquare();
        }


        public void setListAllotmentName(ICollection<Model.Allotment> list)
        {
            Allotmentdd.ItemsSource = list;
        }


    }
}
